﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPMS.Commons.Configuration;

namespace SPMS.Log.Configuration.Handler
{
    /// <summary>
    /// 日志追加器引用节点解析器
    /// </summary>
    /// <remarks>用于处理日志追加器引用节点</remarks>
    /// <history>
    /// [zanezeng]               2009/10/15 14:31    创建
    /// </history>
    public sealed class AppenderRef_NodeHandler : AbstractNodeHandler
    {
        /// <summary>
        /// 处理指定的节点
        /// </summary>
        /// <param name="node">配置节点</param>
        /// <param name="context">处理上下文</param>
        /// <returns>根据配置信息创建的对象</returns>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]   2008-11-17 11:39    Created
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/10/15 14:31    创建
        /// </history>
        protected override object ProcessInternal( IConfigurationNode node, ParseContext context )
        {
            //获得引用的日志追加器
            string appenderName = this.GetAttributeValue( node, LogConfiguationTags.ATTRIBUTE_NAME, context );

            //判断是否指定了追加器的名称
            if (string.IsNullOrEmpty( appenderName ))
            {
                //抛出异常
                throw new ConfigurationException( string.Format( Properties.Resources.MSG_CONFIGURATION_ATTRIBUTE_REQUIRED, node.Name, LogConfiguationTags.ATTRIBUTE_NAME ), node );
            }

            //返回引用的日志追加器的名称
            return appenderName;
        }
    }
}
